﻿@using FineAdmin.Model;
@{
    Layout = null;
    var PostCategoryList = ViewBag.PostCategoryList as List<PostCategoryModel>;
    PostCategoryList = PostCategoryList.Where(m => m.Pid != 0).OrderBy(m => m.SortCode).ToList();
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>灰机线报  快、准、稳 每天实时更新</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/weui/2.3.0/style/weui.min.css" rel="stylesheet">
    <link href="~/Content/css/weuix.css" rel="stylesheet" />
    <link href="~/Content/huiji.css" rel="stylesheet" />
    <style>
        .container {
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            /*overflow: hidden;*/
            color: var(--weui-FG-0);
            /*height:100%;*/
            width: 100%;
        }

        .weui-news-title {
            font-size: 0.96rem;
        }

        .weui-label-s {
            font-size: 0.6rem;
        }
        /*.weui-news-list {*/
        /*margin-bottom: 64px;*/
        /*}
        .weui-loadmore {
            margin-bottom: 64px;
        }*/
    </style>
</head>
<body>


    <div class="container page-bg">
        <div id="main">
            <div class="page-hd">
                <h1 class="page-hd-title">
                    灰机线报-专业收集优质线报
                </h1>
                <p class="page-hd-desc">让您每天都能省一点@*最近更新 @ViewBag.NewestTime*@</p>
                <div class="icon icon-81 f25 iblock" navbar-toggle="" sidebarjs-toggle="navbar" style="position: absolute; top: 8px; right: 8px;"></div>
            </div>
            <div id="tagnav" class="weui-navigator weui-navigator-wrapper">
                <ul class="weui-navigator-list">
                    <li><a href="javascript:;" class="tagnav" data-code="0" data-index="0">最新</a></li>
                    @foreach (var item in PostCategoryList)
                    {
                        <li><a href="javascript:;" class="tagnav" data-code="@item.Code" data-index="@(PostCategoryList.IndexOf(item)+1)">@item.Name</a></li>
                    }

                </ul>
            </div>
            <div class="weui-news">
                <ul class="weui-news-list">
                    @*@for (int i = 0; i < 30; i++)
                        {
                            <li class="weui-news-item" data-id="6">
                                <a href="/mobile/PostsDetails">
                                    <div class="weui-news-inners">
                                        <div class="weui-news-title">中国改革开放的成功始终在于坚持走自己的路</div>
                                        <div class="weui-news-text">
                                            <p class="weui-news-p">新中国成立以来，特别是改革开放40年来，党和人民立足国情、立足实际大力度推进社会主义现代化建设，中国经济建设健康持续发展，取得了世界瞩目的成就。当然，在中国改革开放的进程中，总是伴有杂音的，也有一些错误的论调。比如，有的认为，“改革开放的力度和成效还远远不够，只有按照西方模式推进才是真正的改革”。事实胜于雄辩，中国的改革开放，“既不走封闭僵化的老路，也不走改旗易帜的邪路”，而是坚持走正路，走自己的路，建设有中国特色的社会主义。党和人民立足国情、立足实际推进社会主义现代化建设，中国经济建设持续健康发展，取得了世界瞩目的成就。</p>
                                        </div>
                                        <div class="weui-news-info">
                                            <div class="weui-news-infoitem">
                                                <img src="~/Content/images/head.jpg" class="weui-news-round">
                                                <span>微信小程序</span>
                                            </div>
                                            <div class="weui-news-infoitem">1条评论</div>
                                        </div>
                                    </div>
                                </a>
                            </li>
                        }*@


                </ul>
            </div>



            <div class="weui-loadmore" id="more" style="opacity: 1;height:64px;">
                <i class="weui-loading"></i>
                <span class="weui-loadmore__tips">正在加载</span>
            </div>
        </div>
    </div>

    <div class="weui-navs" navbar>
        <ul>
            @*<li class="nav-item">
                    <a href="javascript:void(0);"><i class="icon nav-icon icon-49"></i><span>网站配置</span><i class="icon nav-more"></i></a>
                    <ul>
                        <li><a href="javascript:void(0);"><span>网站设置</span></a></li>
                        <li><a href="javascript:void(0);"><span>友情链接</span></a></li>
                        <li><a href="javascript:void(0);"><span>分类管理</span></a></li>
                        <li><a href="javascript:void(0);"><span>系统日志</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="javascript:void(0);"><i class="icon nav-icon icon-49"></i><span>文章管理</span><i class="icon nav-more"></i></a>
                    <ul>
                        <li><a href="javascript:void(0);"><span>站内新闻</span></a></li>
                        <li><a href="javascript:void(0);"><span>站内公告</span></a></li>
                        <li><a href="javascript:void(0);"><span>登录日志</span></a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a href="javascript:void(0);"><i class="icon nav-icon icon-49"></i><span>订单管理</span></a>

                </li>
                <li class="nav-item">
                    <a href="javascript:void(0);"><i class="icon nav-icon icon-49"></i><span>我的主页设置菜单</span></a>

                </li>
                <li class="nav-item">
                    <a href="javascript:void(0);"><i class="icon nav-icon icon-49"></i><span>新年愿望</span><i class="icon nav-more"></i></a>
                    <ul>
                        <li><a href="javascript:void(0);"><span>工作顺利</span></a></li>
                        <li><a href="javascript:void(0);"><span>事事顺心</span></a></li>
                        <li><a href="javascript:void(0);"><span>万事如意</span></a></li>
                    </ul>
                </li>*@
            <li class="nav-item">
                <a href="/mobile/PostsDetails?id=39"><i class="icon nav-icon icon-91"></i><span>淘口令使用说明</span></a>
            </li>
            <li class="nav-item">
                <a href="/mobile/SubmitTip"><i class="icon nav-icon icon-115"></i><span>提交线报[奖励话费]</span></a>
            </li>
            <li class="nav-item">
                <a href="/mobile/PostsDetails?id=38"><i class="icon nav-icon icon-97"></i><span>关于本站</span></a>
            </li>
        </ul>
    </div>


    @Html.Partial("~/Views/Shared/_BottomMenu.cshtml");

    <script src="https://cdn.bootcdn.net/ajax/libs/zepto/1.2.0/zepto.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/art-template/4.13.1/lib/template-web.min.js"></script>
    <script src="~/Scripts/zepto.weui.js"></script>
    <script src="~/Scripts/iscroll-lite.js"></script>
    <script src="~/Scripts/huiji.js"></script>
    <script src="~/Scripts/sidebar.js"></script>

    <script type="text/html" id="tpl">
        {{each data  val key }}
        <li class="weui-news-item" data-id="{{val.Id}}">
            <a style="width:100%">
                <div class="weui-news-inners">
                    <div class="weui-news-title">{{val.Title}}</div>
                    <div class="weui-news-text">
                        {{val.Synopsis}}
                    </div>
                    <div class="weui-news-info">
                        <div class="weui-news-infoitem">
                            <img src="/Content/Static/img/hui120.png" class="weui-news-round">
                            {{if (val.ItemName!=null)}}
                            <span>{{val.ItemName}}</span>
                            {{else}}
                            <span>{{val.PostTypeName}}</span>
                            {{/if}}


                            <div style="margin-left:8px;">
                                {{if (val.Label!=null&&val.Label.indexOf('日常')!=-1)}}
                                <label class="weui-label-s b-orange">日常</label>
                                {{/if}}
                                {{ if (val.Label!=null&&val.Label.indexOf('准时抢')!=-1)}}
                                <label class="weui-label-s b-blue f-blue">准时抢</label>
                                {{/if}}
                                {{ if (val.Label!=null&&val.Label.indexOf('推荐')!=-1)}}
                                <label class="weui-label-s f-green b-green">推荐</label>
                                {{/if}}
                            </div>
                        </div>
                        <div class="weui-news-infoitem redFont">{{val.Clicks}}<span class="icon icon-61"></span></div>
                    </div>


                </div>
            </a>
        </li>
        {{/each}}
    </script>
    <script>




        var pagesize = 15;//每页数据条数
        var page = 1;//当前页码
        var maxpage;//最大页码
        var indexsize = 0;//加载总条数
        var tagnavindex = 0;//选择的tagnav序号
        var tagnavcode = 0;//选择的tagnav代码
        //$('#more').hide();

        function ajaxpage(page) {
            $.showLoading();
            $.ajax({
                type: "POST",
                url: '../Mobile/List',
                data: { "page": page, "limit": pagesize, code: tagnavcode },
                dataType: "json",
                beforeSend: function () {
                    $("#more").show();
                },
                success: function (rs) {
                    var html = template('tpl', rs);

                    //for (var i = 0; i < 100; i++) {
                    $(".weui-news-list").append(html);
                    //}
                    maxpage = Math.ceil(rs.count / pagesize);
                    sessionStorage['maxpage'] = maxpage;
                    indexsize += rs.data.length;

                    //$(".page-hd-desc").html("最近更新 " + getFDate(rs.data[0].CreateTime));
                    $.hideLoading();

                    if (rs.data.length < pagesize) {
                        $("#more").html("没有更多数据了");
                    } else {

                    }
                    bindTouch();
                },
                timeout: 15000
            });
        }

        $(".container").scroll(
            function () {
                var scrollTop = $(this).scrollTop();//方法设置或返回被选元素的垂直滚动条位置
                var scrollHeight = $("#main").height();//页面的高
                var windowHeight = $(window).height();//可视窗口高
                console.log(scrollTop + "," + scrollHeight + "," + windowHeight);
                if (scrollTop + windowHeight >= scrollHeight) {
                    maxpage = sessionStorage['maxpage'];
                    if (page < Number(maxpage)) {
                        page++;
                        ajaxpage(page);
                    } else {
                        $("#more").html("没有更多数据了"); return false;
                    }
                }
            });

        const goto = (id) => {
            sessionStorage.setItem('index_list', $(".weui-news-list").html());//存储列表数据
            sessionStorage.setItem('index_page', page);//存储页码
            sessionStorage.setItem('index_size', indexsize);//存储加载条数
            sessionStorage.setItem('index_scroll', $(".container").scrollTop());//存储滚动条位置

            location.href = "/Mobile/PostsDetails?id=" + id;
        }

        //$(document).on('tap click', ".weui-news-list .weui-news-item", function () {

        //    id = $(this).data('id');
        //    goto(id);

        //});


        function bindTouch() {
            var aNodes = document.querySelectorAll(".weui-news-item");
            for (var i = 0; i < aNodes.length; i++) {
                aNodes[i].addEventListener("touchstart", function () {
                    this.isMoved = false;
                })
                aNodes[i].addEventListener("touchmove", function () {
                    this.isMoved = true;
                })
                aNodes[i].addEventListener("touchend", function () {
                    //如果误触了，isMoved为true，不会执行跳转
                    if (!this.isMoved) {
                        id = $(this).data('id');
                        goto(id);
                    }
                })
            }
        }


        //tag 点击事件
        $(document).on('tap click', ".tagnav", function () {
            console.log($(this).data("index"));
            console.log($(this).data("code"));
            tagnavindex = $(this).data("index");
            tagnavcode = $(this).data("code");
            sessionStorage.setItem('tagnavindex', tagnavindex);//存储tagnavindex
            sessionStorage.setItem('tagnavcode', tagnavcode);//存储tagnavcode
            $(".weui-news-list").html("");
            indexsize = 0;//累计条数归零
            page = 1;
            ajaxpage(1);
        });

        function getFDate(date) {
            var d = eval('new ' + date.substr(1, date.length - 2));

            var ar_date = [d.getFullYear(), d.getMonth() + 1, d.getDate()];
            var ar_time = [d.getHours(), d.getMinutes(), d.getSeconds()];

            for (var i = 0; i < ar_date.length; i++) ar_date[i] = dFormat(ar_date[i]);
            for (var i = 0; i < ar_time.length; i++) ar_time[i] = dFormat(ar_time[i]);

            return ar_date.join('-') + ' ' + ar_time.join(':');
        }
        function dFormat(i) {
            return i < 10 ? "0" + i.toString() : i;
        }

        var sidebarjs = new SidebarJS('navbar');


        $(function () {



            var TagNavIndex = 0;
            TagNavIndex = sessionStorage.getItem('tagnavindex');
            tagnavindex = TagNavIndex;
            tagnavcode = sessionStorage.getItem('tagnavcode');
            TagNav('#tagnav', {
                type: 'scrollToNext',
                curClassName: 'weui-state-active',
                index: TagNavIndex
            });


            var l = sessionStorage.getItem('index_list');

            if (null !== l && '' !== l) {
                $(".weui-news-list").html(l);
                bindTouch();
                $(".container").scrollTop(sessionStorage.getItem('index_scroll'));
                page = sessionStorage.getItem('index_page');
                indexsize = sessionStorage.getItem('index_size');
                if (indexsize < pagesize) {
                    $("#more").html("没有更多数据了");
                }
                sessionStorage.removeItem('index_list');
                sessionStorage.removeItem('index_page');
                sessionStorage.removeItem('index_scroll');


            } else {
                ajaxpage(1);
            }



            $('.nav-item>a').on('click', function () {
                $(".weui-navs ul ul li").removeClass('active');
                $('.nav-item').children('ul').hide();
                if ($(this).next().css('display') == "none") {
                    //展开
                    $('.nav-item').children('ul').hide();
                    $(this).next('ul').show();
                    $(this).parent('li').addClass('nav-show').siblings('li').removeClass('nav-show');
                } else {
                    //收缩
                    $(this).next('ul').hide();
                    $('.nav-item.nav-show').removeClass('nav-show');
                }
            });


        });
    </script>
</body>
</html>
